package AgentTravel.Behaviours;

import java.io.IOException;

import AgentTravel.MyOntology;
import AgentTravel.LogicObjects.City;
import AgentTravel.LogicObjects.UserProfile;
import jade.core.behaviours.CyclicBehaviour;
import jade.domain.DFService;
import jade.domain.FIPAException;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.domain.FIPAAgentManagement.ServiceDescription;
import jade.lang.acl.ACLMessage;
import jade.lang.acl.MessageTemplate;
import jade.lang.acl.UnreadableException;

public class GetProfileRequestBehaviour extends CyclicBehaviour 
{
	UserProfile profile;
	
	public GetProfileRequestBehaviour(UserProfile profile)
	{
		this.profile=profile;
	}

	@Override
	public void action() 
	{
		MessageTemplate mt=MessageTemplate.MatchPerformative(ACLMessage.REQUEST);
		ACLMessage msg = myAgent.receive(mt);
				
		if (msg != null) 
		{
			System.out.println("Odebralem RequestProfile: ");
			System.out.println("Od: " + msg.getSender());
			
			// dostalem zapytanie o profil
			if(msg.getContent().equals(MyOntology.requestProfileText))
			{
				ACLMessage reply=msg.createReply();
				try 
				{
					reply.setContentObject(profile);
				} 
				catch (IOException e) 
				{
					e.printStackTrace();
				}
				reply.setPerformative(ACLMessage.INFORM_REF);
				myAgent.send(reply);
			}		
		}
		else 
		{
			block();
		}
		
	}

}
